package com.tsing.wms.controller;


import com.tsing.wms.service.ISupplierService;
import com.tsing.wms.util.ResultUtil;
import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.valid.UpdateGroup;
import com.tsing.wms.vo.PageResultVO;
import com.tsing.wms.vo.ResultData;
import com.tsing.wms.vo.req.IdReqVO;
import com.tsing.wms.vo.req.IdsReqVO;
import com.tsing.wms.vo.req.SupplierPageReqVO;
import com.tsing.wms.vo.req.SupplierReqVO;
import com.tsing.wms.vo.resp.IdAndNameRespVO;
import com.tsing.wms.vo.resp.SupplierRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 供应商表 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2022-04-13
 */
@Api(tags = "供应商管理")
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private ISupplierService supplierService;

    @GetMapping("/userList")
    @ApiOperation(value = "用户列表")
    public ResultData<List<IdAndNameRespVO>> userList() {
        return ResultUtil.success(supplierService.userList());
    }

    @GetMapping("/regionList")
    @ApiOperation(value = "区域列表")
    public ResultData<List<IdAndNameRespVO>> regionList() {
        return ResultUtil.success(supplierService.regionList());
    }

    @PostMapping("/addSupplier")
    @ApiOperation(value = "新增供应商")
    public ResultData addSupplier(@Validated({AddGroup.class}) @RequestBody SupplierReqVO reqVO, HttpServletRequest request) {
        supplierService.addSupplier(reqVO, request);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteSupplier")
    @ApiOperation(value = "删除供应商")
    public ResultData deleteSupplier(@Validated @RequestBody IdsReqVO reqVO, HttpServletRequest request) {
        supplierService.deleteSupplier(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/getSupplier")
    @ApiOperation(value = "查询供应商详情")
    public ResultData<SupplierRespVO> getSupplier(@Validated IdReqVO reqVO) {
        return ResultUtil.success(supplierService.getSupplier(reqVO));
    }

    @PutMapping("/updateSupplier")
    @ApiOperation(value = "修改供应商")
    public ResultData updateSupplier(@Validated({UpdateGroup.class}) @RequestBody SupplierReqVO reqVO, HttpServletRequest request) {
        supplierService.updateSupplier(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/supplierPage")
    @ApiOperation(value = "供应商分页")
    public ResultData<PageResultVO<SupplierRespVO>> supplierPage(@Validated SupplierPageReqVO reqVO) {
        return ResultUtil.success(supplierService.supplierPage(reqVO));
    }

}
